 @@include('./_config.js');
 require(['jquery','./_common'],function($){
    var selectIndex = [];
    var $currentQuestion;
    Array.prototype.indexOf = function(val) {              
        for (var i = 0; i < this.length; i++) {  
            if (this[i] == val) return i;  
        }  
        return -1;  
    };  
    Array.prototype.remove = function(val) {  
        var index = this.indexOf(val);  
        if (index > -1) {  
            this.splice(index, 1);  
        }  
    }; 
    Array.prototype.add = function(val) {  
        var index = this.indexOf(val);  
        if (index > -1) return;
        else{
            this.push(val);
        }
    };
    function hideSlected($questions){
        selectIndex.map(function(el){
            $questions.children('li').eq(el).hide();
        })
    }
    $('#setQuestion').find('.selectQuestion').click(function(e){
        e.stopPropagation();
        var $questions = $(this).nextAll('.questions')
        hideSlected($questions)
        $currentQuestion && $currentQuestion.hide() && $currentQuestion.parent().removeClass('expandQuestion');
        $questions.slideDown();
        $(this).parent().addClass('expandQuestion');
        $currentQuestion = $questions;
    })

    $('#setQuestion').find('.questions li').click(function(e){
        e.stopPropagation();
        var text = $(this).text();
        var $selectQuestion = $currentQuestion.prevAll('.selectQuestion')
        $currentQuestion && $selectQuestion.val(text);
        var $parent = $(this).parent();
        var currentIndex = $parent.attr('data-index');
        currentIndex && selectIndex.remove(currentIndex);
        var index = $(this).index();
        selectIndex.add(index);
        $parent.attr('data-index',index);
        $parent.hide();
        $parent.parent().removeClass('expandQuestion');
        $selectQuestion.trigger('change');
    })
    $('body').click(function(){
        $currentQuestion && $currentQuestion.hide() && $currentQuestion.parent().removeClass('expandQuestion');;
    })

    var $allInput = $('#setQuestion').find('input');
    var inputArray = $allInput.toArray();
    $allInput.on('change',function(){
        var totalNull = 0;
        inputArray.map(function(el){
            if($(el).val() !='') totalNull++;
        })
        if(totalNull == inputArray.length){
            $('#submit').removeClass('submitDefault');
        } 
        else{
            $('#submit').addClass('submitDefault');
        }
    })
    //提交操作
    $('#submit').click(function(){
        if($(this).hasClass('submitDefault')) return;
        /*
            添加提交操作
        */
    })
 })
